/*
 * 3.2.cpp
 *
 *  Created on: 2012-5-17
 *      Author: jawinton
 */


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>

using namespace std;

int main (void) {
	char skew[32];
	while (true) {
		cin >> skew;
		if (skew[0] == '0' && skew[1] == '\0') break;
		int len = strlen(skew);
		int value = 0, notZero = 0;
		for (int i=0; i<len; i++) {
			if (skew[i] == '1') {
				notZero ++;
				value += 1;
			} else if (skew[i] == '2') {
				notZero += 2;
				value += 2;
			}
			value *= 2;
		}
		value -= notZero;
		cout << value << endl;;
	}

	return 0;
}
